import { UserTypeEnum, IsActiveEnum } from "@/enum/user.js";
import { ReviewStatusEnum } from "@/enum/review"
import { ImageTypeEnum } from "@/enum/banners"
import { CommunityTypeEnum } from "@/enum/area"
import { TaskCategoryEnum, OrderTypeEnum } from "@/enum/order"

export const getUserType = (data) => {
  return {
    ...data,
    userType: UserTypeEnum[data.userType],
    isActive: IsActiveEnum[data.isActive]
  }
}

// 获取用户类型,激活状态
export const getUserData = (data) => {
  return data.map((item) => {
    return getUserType(item)
  })
}
export const getReviewStatusItem = (data) => {
  return {
    ...data,
    auditStatus: ReviewStatusEnum[data.auditStatus]
  }
}
// 获取审核状态
export const getReviewStatus = (data) => {
  return data.map((item) => {
    return getReviewStatusItem(item)
  })
}

// 创建审核状态反向映射
const reviewStatusEnumReverse = Object.fromEntries(
  Object.entries(ReviewStatusEnum).map(([key, value]) => [value, key])
);

// 由审核状态获取审核码
export const getReviewCode = (data) => {
  return {
    ...data,
    auditStatus: reviewStatusEnumReverse[data.auditStatus] || data.auditStatus
  }
}

// 获取banners类型
export const getBannersType = (data) => {
  return data.map((item) => {
    return {
      ...item,
      type: ImageTypeEnum[item.type]
    }
  })
}
// 创建小区类型反向映射
const communityEnumReverse = Object.fromEntries(
  Object.entries(CommunityTypeEnum).map(([key, value]) => [value, key])
);
// 获取小区类型码
export const getCommunityCode = (data) => {
  return {
    ...data,
    type: communityEnumReverse[data.type] || data.type
  }
}

// 获取小区类型
export const getCommunityType = (data) => {
  return data.map((item) => {
    return {
      ...item,
      type: CommunityTypeEnum[item.type]
    }
  })
}

// 创建banners类型反向映射
const bannerEnumReverse = Object.fromEntries(
  Object.entries(ImageTypeEnum).map(([key, value]) => [value, key])
);
// 获取小区类型码
export const getBannerTypeCode = (data) => {
  return {
    ...data,
    type: bannerEnumReverse[data.type] || data.type
  }
}

// 获取订单类型、订单状态
export const getOrder = (data) => {
  return data.map((item) => {
    return {
      ...item,
      status: OrderTypeEnum[item.status],
      taskCategoryId: TaskCategoryEnum[item.taskCategoryId]
    }
  })
}

